<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>

<body>
    <script>
        var parent = document.createElement("div");
        var child = document.createElement("p");
        parent.appendChild(child);
        var span = document.createElement("span");

        child.replaceWith(span);

        console.log(parent.outerHTML);
        // "<div><span></span></div>"
    </script>
</body>

</html>